package com.manopservice.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.manopservice.model.CarAutoPartSide;


@Repository("carAutoPartSideDAO")
public class CarAutoPartSideDAOImpl implements CarAutoPartSideDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void save(CarAutoPartSide carAutoPartSide) {
		sessionFactory.getCurrentSession().saveOrUpdate(carAutoPartSide);
		
	}

	@Override
	public void delete(int id) {
		CarAutoPartSide carAutoPartSide = (CarAutoPartSide) sessionFactory.getCurrentSession().get(CarAutoPartSide.class, id);
		sessionFactory.getCurrentSession().delete(carAutoPartSide);
		
	}

	@SuppressWarnings("unchecked")
	public List<CarAutoPartSide> findAll() {
		
		return (List<CarAutoPartSide>) sessionFactory.getCurrentSession().createCriteria(CarAutoPartSide.class).list();
	}

	@Override
	public CarAutoPartSide findById(int id) {

		return (CarAutoPartSide) sessionFactory.getCurrentSession().get(CarAutoPartSide.class, id);
	}

}
